package com.mly.data.algo.designMode.State;

public class MarioStateMachine {
    private int score;
    //    private State currentState;
    private IMario currentState;// 不再使用枚举来表示状态

    public MarioStateMachine() {
        this.score = 0;
//        this.currentState = State.SMALL;
        this.currentState = new SmallMario(this);
    }

    //状态机实现方式一：分支逻辑法

//    public void obtainMushRoom() {
//        if (currentState.equals(State.SMALL)) {
//            this.currentState = State.SUPER;
//            this.score += 100;
//        }
//    }
//
//    public void obtainCape() {
//        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER)) {
//            this.currentState = State.CAPE;
//            this.score += 200;
//        }
//    }
//
//    public void obtainFireFlower() {
//        if (currentState.equals(State.SMALL) || currentState.equals(State.SUPER)) {
//            this.currentState = State.FIRE;
//            this.score += 300;
//        }
//    }
//
//    public void meetMonster() {
//        if (currentState.equals(State.SUPER)) {
//            this.currentState = State.SMALL;
//            this.score -= 100;
//            return;
//        }
//        if (currentState.equals(State.CAPE)) {
//            this.currentState = State.SMALL;
//            this.score -= 200;
//            return;
//        }
//        if (currentState.equals(State.FIRE)) {
//            this.currentState = State.SMALL;
//            this.score -= 300;
//            return;
//        }
//
//    }


    //状态机实现方式二：查表法
//    private static final State[][] transitionTable = {
//            {State.SUPER, State.CAPE, State.FIRE, State.SMALL},
//            {State.SUPER, State.CAPE, State.FIRE, State.SMALL},
//            {State.CAPE, State.CAPE, State.CAPE, State.SMALL},
//            {State.FIRE, State.FIRE, State.FIRE, State.SMALL}
//    };
//    private static final int[][] actionTable = {
//            {+100, +200, +300, +0},
//            {+0, +200, +300, -100},
//            {+0, +0, +0, -200},
//            {+0, +0, +0, -300}
//    };
//
//
//    public void obtainMushRoom() {
//        executeEvent(Event.GOT_MUSHROOM);
//    }
//
//    public void obtainCape() {
//        executeEvent(Event.GOT_CAPE);
//    }
//
//    public void obtainFireFlower() {
//        executeEvent(Event.GOT_FIRE);
//    }
//
//    public void meetMonster() {
//        executeEvent(Event.MET_MONSTER);
//    }
//
//    private void executeEvent(Event event) {
//        int stateValue = currentState.getValue();
//        int eventValue = event.getValue();
//        this.currentState = transitionTable[stateValue][eventValue];
//        this.score += actionTable[stateValue][eventValue];
//    }

    public void obtainMushRoom() {
        this.currentState.obtainMushRoom();
    }

    public void obtainCape() {
        this.currentState.obtainCape();
    }

    public void obtainFireFlower() {
        this.currentState.obtainFireFlower();
    }

    public void meetMonster() {
        this.currentState.meetMonster();
    }


    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

//    public State getCurrentState() {
//        return this.currentState;
//    }

    public State getCurrentState() {
        return this.currentState.getName();
    }

    public void setCurrentState(IMario currentState) {
        this.currentState = currentState;
    }
}
